package com.youdianda.controller;

import com.youdianda.dto.MyArticleQueryDTO;
import com.youdianda.dto.UpdateCollectOrZanDTO;
import com.youdianda.dto.UserDataListDTO;
import com.youdianda.entity.YddArticle;
import com.youdianda.entity.YddUser;
import com.youdianda.result.PageResult;
import com.youdianda.result.Result;
import com.youdianda.service.IYddUserService;
import com.youdianda.vo.UserInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Api(tags = "前台用户信息相关接口")
public class YddUserInfoController {

    @Autowired
    private IYddUserService iYddUserService;

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/getUserInfo")
    @ApiOperation(value = "获取用户信息")
    public Result<UserInfoVo> getUserData(){
        return iYddUserService.getUserDataFront();
    }

    /**
     * 获取我的文章信息
     * @param dto
     * @return
     */
    @GetMapping("/myArticle")
    @ApiOperation(value = "获取我的文章信息")
    public Result<PageResult> getMyArticle(MyArticleQueryDTO dto){
        return iYddUserService.getMyArticle(dto);
    }

    /**
     * 获取我的收藏/点赞文章
     * @param dto
     * @return
     */
    @GetMapping("/userDataList")
    @ApiOperation(value = "获取我的收藏/点赞文章")
    public Result getUserDataList(UserDataListDTO dto){
        return iYddUserService.getUserDataList(dto);
    }

    /**
     * 修改用户资料，这里不需要先回显再查询，因为回显数据从/getUserInfo中获取
     * @param yddUser
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改用户资料")
    public Result updateUser(@RequestBody YddUser yddUser){
        return iYddUserService.updateUser(yddUser);
    }


    /**
     * 点赞/取消点赞和收藏/取消收藏
     * @param dto
     * @return
     */
    @GetMapping("/userDataHandle")
    @ApiOperation(value = "点赞/取消点赞和收藏/取消收藏")
    public Result updateCollectOrZan(UpdateCollectOrZanDTO dto){
        return iYddUserService.updateCollectOrZan(dto);
    }


    /**
     * 发布文章
     * @return
     */
    @PostMapping("/addArticle")
    @ApiOperation(value = "发布文章")
    public Result addArticle(@RequestBody YddArticle yddArticle) {
        return  iYddUserService.addArticle(yddArticle);
    }

    /**
     * 删除文章
     * @param
     * @return
     */
    @GetMapping("/delArticle")
    @ApiOperation(value = "删除文章")
    public Result delArticle(Integer id) {
        return iYddUserService.delArticle(id);
    }

    /**
     * 修改文章
     * @param
     * @return
     */
    @PostMapping("/editArticle")
    @ApiOperation(value = "修改文章")
    public Result editArticle(@RequestBody YddArticle yddArticle) {
        return iYddUserService.editArticle(yddArticle);
    }

}
